package com.alkaid.novel.controller;

import com.alkaid.commons.controller.BaseController;
import com.alkaid.commons.entity.AnimePageEntity;
import com.alkaid.commons.entity.Novel;
import com.alkaid.commons.utils.JsonResult;
import com.alkaid.novel.service.NovelService;
import com.github.pagehelper.PageInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Kylin
 */
@RestController
@RequestMapping("api/novel")
public class NovelController extends BaseController {

    private final NovelService novelService;

    public NovelController(NovelService novelService) {
        this.novelService = novelService;
    }

    /**
     * 热度排行
     *
     * @param num the num
     * @return the hot list
     */
    @GetMapping("/hot_list/{num}")
    public JsonResult<List<Novel>> getHotList(@PathVariable Integer num) {
        List<Novel> lists = novelService.getHotList(num);
        return new JsonResult<>(200, lists, "success");
    }

    /**
     * 小说列表排序
     *
     * @param page 页面
     * @return {@link JsonResult}<{@link PageInfo}<{@link Novel}>>
     */
    @PostMapping("/all")
    public JsonResult<PageInfo<Novel>> getAll(@Validated AnimePageEntity page) {
        PageInfo<Novel> pageInfo = novelService.getAll(page);
        return new JsonResult<>(200, pageInfo, "success");
    }

    /**
     * 播放量排行
     *
     * @param num the num
     * @return the count list
     */
    @GetMapping("/count_list/{num}")
    public JsonResult<List<Novel>> getCountList(@PathVariable int num) {
        List<Novel> lists = novelService.getCountList(num);
        return new JsonResult<>(200, lists, "success");
    }

    @GetMapping("/play/ss/{id}")
    public JsonResult<Novel> getNovelPlayByNovelId(@PathVariable Integer id) {
        Novel novel = novelService.getNovelWithDetailsByNovelId(id);
        return new JsonResult<>(200, novel, "success");
    }
}
